home *** CD-ROM | disk | FTP | other *** search
/ IRIX Installation Tools & Overlays 2002 November / SGI IRIX Installation Tools & Overlays 2002 November - Disc 4.iso / dist / infosearch.idb / usr / lib / infosearch / bin / relnote2html.pl.z / relnote2html.pl
Text File  |  2002-10-15  |  13KB  |  538 lines

  1. #
  2. # relnote2html.pl
  3. #
  4. # Copyright 1996-2002, Silicon Graphics, Inc.
  5. # All Rights Reserved.
  6. #
  7. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  8. # the contents of this file may not be disclosed to third parties, copied or
  9. # duplicated in any form, in whole or in part, without the prior written
  10. # permission of Silicon Graphics, Inc.
  11. #
  12. # RESTRICTED RIGHTS LEGEND:
  13. # Use, duplication or disclosure by the Government is subject to restrictions
  14. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  15. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  16. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  17. # rights reserved under the Copyright Laws of the United States.
  18. #
  19. # requires perl5 and format2html.pl
  20. #
  21.  
  22. require 'format2html.pl';
  23.  
  24.  
  25. #######################################################################
  26. #
  27. # void relnotes2html($root, $fname, $srch_str)
  28. #
  29. #######################################################################
  30.  
  31. sub relnotes2html {
  32.  
  33.     # Supports input in the following forms:
  34.     #
  35.     # /usr/relnotes/dmedia/ch1.z
  36.     # TC desktop_eoe
  37.     # desktop_eoe
  38.  
  39.     my($in_rnroot, $in_fname, $in_srch, $in_bld) = @_;
  40.  
  41.     if( $in_fname eq '' ) {
  42.         print "relnotes2html: filename not specified" if($_WEB == 0);
  43.         return;
  44.     }
  45.  
  46.     my($rnroot,$product,$productbase,$tmp,$toc,$rncmd) = '';
  47.     if($in_rnroot ne '/' && $in_rnroot ne '') {
  48.        $rnroot = $in_rnroot; 
  49.     }
  50.  
  51.     my($rnpath) = "$rnroot/usr/relnotes";
  52.     $ENV{'RELNOTESPATH'} = $rnpath;
  53.  
  54.     &buildExpression($in_srch);
  55.  
  56.     my($fname) = $in_fname;
  57.     $fname =~ s/^TC[\s]+//;
  58.  
  59.  
  60.     # support for HTML release notes (a gzipped package)
  61.     #
  62.     if ($fname =~ /\.gz$/m){
  63.  
  64.         if($rnroot && $fname !~ /^$rnroot/){
  65.        &outputHTMLPage("$rnroot/$fname");
  66.         }else{
  67.        &outputHTMLPage($fname);
  68.         }
  69.     return; 
  70.     }
  71.  
  72.     if($fname =~ /\/([^\/]+)\/ch\w+\.z/) {
  73.  
  74.        $product = $1;
  75.        $tmp = $fname;
  76.  
  77.        if (-e $tmp && $product =~ /^$rnpath/){
  78.            $tmp =~ s/ch(0)?1.z//;
  79.            $productbase = $tmp;
  80.            $toc = $fname;
  81.            $toc =~ s/ch(0)?1.z/TC/;
  82.        } else {
  83.            $productbase = "$rnpath/$product";
  84.            $toc = "$rnpath/$product/TC";
  85.        }
  86.  
  87.     } else {  
  88.  
  89.         $product = $fname;
  90.         if( $product =~ /\// ) {
  91.             $fname =~ /\/([^\/]+)$/;
  92.             $product = $1;
  93.         }
  94.         $productbase = $rnpath . '/' . $product;
  95.         my($htmlfile) = $productbase . '/' . $product . '.gz';
  96.  
  97.         if( -r $htmlfile){
  98.             &outputHTMLPage($htmlfile);
  99.             return;
  100.         } else {
  101.  
  102.             $toc = $productbase . '/TC';
  103.             if (-e $toc){
  104.  
  105.                 ;  # continue on
  106.  
  107.             } else {
  108.  
  109.                 # need to find this, in a *case-insensitive* way
  110.                 #
  111.                 $rncmd = "/sbin/ls -1 $rnpath | grep -i \"$product\" |";
  112.                 my(@rnfiles) = &findRnMatches($productbase, $rncmd, $rnpath);
  113.  
  114.                 # release note found
  115.                 #
  116.                 if ($#rnfiles == 0) {
  117.  
  118.                     $htmlfile = $rnfiles[0] . '/' . $product . '.gz';
  119.                     if( -r $htmlfile){
  120.                         &outputHTMLPage($htmlfile);
  121.                         return;
  122.                     } else {
  123.  
  124.                         $productbase = $rnfiles[0];
  125.                         $toc = $rnfiles[0] . '/TC';
  126.                     }
  127.  
  128.                 } elsif ($#rnfiles == -1) {
  129.  
  130.                     # No release notes found
  131.                     #
  132.                     &HTMLHeaderFormat("TPL");
  133.                     print "Unable to find release notes for: $product";
  134.                     &HTMLTrailerFormat();
  135.                     return;
  136.                 }
  137.             }
  138.         }
  139.     }
  140.  
  141.     my(@chapter) = &buildRnChapterList($productbase, $toc);  # Read TOC
  142.     if($#chapter == -1) {
  143.        print "Unable to find release notes for: $product" if($_WEB == 0);
  144.        return;
  145.     }
  146.  
  147.     &HTMLHeaderFormat(($in_bld ne '' ? 
  148.                                &getRnTitle($product, $chapter[0]) : $product));
  149.     &bigFormat($product);
  150.  
  151.     my($i) = 0;
  152.     for($i=1; $i < (@chapter + 0); $i++) {
  153.       print "  <A href=\"\#$chapter[$i]\"><b>$chapter[$i]</b></A>\n";
  154.       $i++;
  155.     }
  156.  
  157.     &formatRnChapters(@chapter);
  158.     return;
  159. }
  160.  
  161.  
  162. #######################################################################
  163. #
  164. # findRnMatches(String $rnbase, String $rncmd)
  165. #
  166. # Find release note
  167. #
  168. #######################################################################
  169.  
  170. sub findRnMatches{
  171.  
  172.     my($rnbase,$rncmd,$rnpath) = @_;
  173.     my(@rnfiles) = ();
  174.     open(RNPIPE, $rncmd) || die "$rncmd: !$\n";
  175.  
  176.     while(<RNPIPE>){
  177.         # Get the filename; compare to the size of the base
  178.         s/\n//;
  179.         if($_ ne ""){
  180.            $tmp= sprintf("%s/%s", $rnpath, $_);
  181.            if (length($tmp) == length($rnbase)) {
  182.                push(@rnfiles, $tmp);
  183.            }
  184.         }
  185.     }
  186.  
  187.     return(@rnfiles);
  188. }
  189.  
  190.  
  191. #######################################################################
  192. #
  193. # @toc buildRnChapterList(String "filename of TC")
  194. #
  195. #######################################################################
  196.  
  197. sub buildRnChapterList{
  198.  
  199.     my($productbase, $tcFile) = @_;
  200.     my @chapterlist     = ();
  201.     my @toc             = ();
  202.     my @chapterfilelist = ();
  203.     my $chapternum      = 0;
  204.     my $title           = "";
  205.     my $chapterfile     = "";
  206.     my $s               = "";
  207.  
  208.     if( open(TOC,$tcFile) ) {
  209.  
  210.         # collect all files via table of contents
  211.         #
  212.         while(<TOC>) {
  213.               chop;
  214.               if (/^\d|[A-Z]/) {
  215.                   push(@chapterlist, $_);
  216.               }
  217.         }
  218.         close(TOC);
  219.     }
  220.  
  221.     # check for other files...
  222.     #
  223.     foreach (`cd ${productbase}; /sbin/ls -1 *`) {
  224.         chop;
  225.         if( ${_} =~ /\.gz$/i || ${_} =~ /\.z$/i
  226.             || 
  227.             ${_} eq 'TC' || ${_} =~ /TRANS/) {
  228.             next;
  229.         }
  230.         $s = "${_}\t${_}";
  231.         push(@chapterlist, $s);
  232.     }
  233.  
  234.  
  235.     foreach $chapter (@chapterlist) {
  236.  
  237.         ($chapternum, $title) = split (/\s+/,  $chapter,  2);
  238.         $chapterfile = $productbase . '/ch' . $chapternum . '.z';
  239.         if ( -e $chapterfile && -s $chapterfile > 0 ) {
  240.             push(@chapterfilelist, $chapterfile);
  241.             push(@chapterfilelist, $title);
  242.         } else {
  243.  
  244.             # dmedia, or relnotes with prepended "0"
  245.             #
  246.             $chapterfile =~ s/ch([\d]+)\.z/ch0$1\.z/;
  247.             if ( -e $chapterfile && -s $chapterfile > 0 ) {
  248.                 push(@chapterfilelist, $chapterfile);
  249.                 push(@chapterfilelist, $title);
  250.             } else {
  251.  
  252.                 # other files...
  253.                 $chapterfile = "${productbase}/${chapternum}";
  254.                 if ( -e $chapterfile && -s $chapterfile > 0 ) {
  255.                      push(@chapterfilelist, $chapterfile);
  256.                      push(@chapterfilelist, $title);
  257.                 }
  258.             }
  259.         }
  260.  
  261.     }
  262.  
  263.     return(@chapterfilelist);
  264. }
  265.  
  266.  
  267. #######################################################################
  268. #
  269. # void formatRnChapters(@chapterfilelist)
  270. #
  271. #######################################################################
  272.  
  273. sub formatRnChapters{
  274.  
  275.     my(@chaps) = @_;
  276.     my($pgbrkcfmt) = "./pgbrkcfmt";
  277.     my($chapter,$title_id,$filter,$para) = '';
  278.     my($i) = 0;
  279.     my @paraArray = ();
  280.  
  281.     $/ = undef; # Read in all at once
  282.  
  283.     for($i=0; $i < (@chaps + 0); $i++ ) {
  284.  
  285.         $chapter  = $chaps[$i];
  286.         $i++;
  287.         $title_id = $chaps[$i];
  288.  
  289.         # the sed cmd is to interpert superscripts; must be done before the
  290.         # stream hits col, otherwise formatting is a mess (hence, using sed)
  291.         # couldn't go directly to HTML, cuz the other cmds mangle it
  292.         #
  293.         $filter = "pcat $chapter | col | " .
  294.                   "sed 's/.8r.9/SSrSS/g;s/o.82.9/o2/g' | " .
  295.                   "$pgbrkcfmt ";
  296.         if( $chapter !~ /\.z$/i ) {
  297.             $filter = "cat $chapter ";
  298.         }
  299.  
  300.         open(RNPIPE, "$filter |") || do {
  301.              print "<b>Unable to open $chapter</b>\n";
  302.              return;
  303.         };
  304.  
  305.         print "\n",
  306.           ($i > 1 ? "<center><A href=\"\#X\"><font size=\"-1\">back to top</font></A></center>" : ''),
  307.           "<HR ALIGN=\"left\" WIDTH=\"99%\">\n",
  308.           "<A name=\"$title_id\"><B>$title_id</B></A>\n";
  309.  
  310.         while(<RNPIPE>){
  311.  
  312.          if($_ eq ''){
  313.             next;
  314.          }
  315.  
  316.          # plain text docs...
  317.          if( $filter =~ /^cat/ ) { 
  318.  
  319.              &hilite(\$_);
  320.              print $_;
  321.  
  322.          } else {
  323.  
  324.             $_ =~ s/SSrSS/<sup>r<\/sup>/g;
  325.             $_ =~ s/\+\x8//g;
  326.  
  327.             &pageBreakRemoval(\$_);
  328.  
  329.             if(/\n\n/){
  330.                @paraArray = split(/\n\n+/, $_);
  331.                foreach $para (@paraArray){
  332.                   &formatRnParagraph(\$para);
  333.                   print "\n";
  334.                }
  335.             }else{
  336.                &formatRnParagraph(\$_);
  337.             }
  338.          }
  339.         }
  340.         close(RNPIPE);
  341.     }
  342.  
  343.     print "<center>",
  344.           "<A href=\"\#X\"><font size=\"-1\">back to top</font></A>",
  345.           "</center>",
  346.           "<HR ALIGN=\"left\" WIDTH=\"99%\">\n";
  347.  
  348.     &HTMLTrailerFormat();
  349.     return;
  350. }
  351.  
  352.  
  353. #######################################################################
  354. #
  355. # void formatRnParagraph(String_ref \$buf)
  356. #
  357. # Identify a paragraph
  358. #
  359. #######################################################################
  360.  
  361. sub formatRnParagraph{
  362.  
  363.     my($buf_ref) = @_;
  364.    
  365.     if($$buf_ref eq '') {
  366.     return;
  367.     }
  368.  
  369.     # Remove trailing page numbers
  370.     #
  371.     if($$buf_ref =~ /(<B>)?Page(<\/B>)?\ (<B>)?\d\d?(<\/B>)?/
  372.        ||
  373.        $$buf_ref =~ /^[\s\-]+[\d]+[\s\-]+$/) {
  374.         return;
  375.     }
  376.  
  377.     # At this point we have some sort of body paragraph
  378.     # Apply links and keyword highlighting if necessary
  379.     #
  380.     &addLinks($buf_ref);
  381.     &hilite($buf_ref);
  382.  
  383.     # this is for a named areas
  384.     #
  385.     if($$buf_ref =~ /^[\s]+([\d\.]+)[\s]+<[BI]+>/) {
  386.  
  387.        my($tmp) = $$buf_ref;
  388.        my(@num) = ($1 =~ /\./g);
  389.        
  390.        $tmp =~ s/I>/B>/g;
  391.        $tmp =~ s/\_/\ /g;
  392.  
  393.        if( $tmp =~ /^[\s]+[\d]+[\.]+[\s]+/ ) {
  394.            $tmp =~ s/^[\s]{4}//;
  395.        } elsif( $tmp =~ /^[\s]+[\d]+[\.]+[\d]+[\s]+/ ) {
  396.            $tmp =~ s/^[\s]{5}//;
  397.        }
  398.        print $tmp, "\n", ((@num + 0) == 1 ? "\n" : '');
  399.  
  400.     } else {
  401.  
  402.        print $$buf_ref, "\n";
  403.     }
  404. }
  405.  
  406.  
  407. #######################################################################
  408. #
  409. # string getRnTitle(product, file)
  410. #
  411. #######################################################################
  412.  
  413. sub getRnTitle {
  414.  
  415.     # used in build stage, where speed isn't such an issue
  416.     #
  417.     my($prod, $f) = @_;
  418.     my($ttl) = '';
  419.   
  420.     if( !(-r $f) ) {
  421.         return "$prod";
  422.     }
  423.  
  424.     if( $f =~ /\.gz$/ ) {
  425.         $ttl = &get_rn_gz_title($f);
  426.     } else {
  427.         $ttl = &get_rn_title($f);
  428.     }
  429.  
  430.     return "$ttl";
  431. }
  432.  
  433. sub get_rn_gz_title() {
  434.  
  435.     my($rn) = @_;
  436.     my(@c) = split(/\//, $rn);
  437.     my($buf, $t) = '';
  438.     my($in_id) = 0;
  439.     my($t) = $c[((@c+0)-2)];
  440.  
  441.     open(FP, "gunzip -cd $rn |") || do {
  442.          print "mkrnwrdlist: cannot run title cmd ($rn)\n" if($_WEB == 0);
  443.          return "$t";
  444.     };
  445.  
  446.     while(<FP>) {
  447.          chop;
  448.          if( $_ =~ /<title>(.*?)<\/title>/i ) {
  449.              $buf = $1;
  450.              $buf =~ s/<[^>]*>//gs;
  451.              $buf =~ s/^[\s]+//g;
  452.              $buf =~ s/[\s]+$//g;
  453.              $t .= " : $buf";
  454.              last;
  455.          }
  456.     }
  457.     close(FP);
  458.  
  459.     return "$t";
  460. }
  461.  
  462.  
  463. sub get_rn_title() {
  464.  
  465.     my($rn) = @_;
  466.     my(@c) = split(/\//, $rn);
  467.     my($buf, $t) = '';
  468.     my($in_id) = 0;
  469.     my($t) = $c[((@c+0)-2)];
  470.  
  471.     my($cmd) = '';
  472.     if( $rn =~ /\.z$/ ) {
  473.         $cmd = "pcat $rn | col -xb |";
  474.     } else {
  475.         return "$t";
  476.     }
  477.  
  478.     open(FP, "$cmd") || do {
  479.          print "mkrnwrdlist: cannot run title cmd ($rn)\n" if($_WEB == 0);
  480.          return "$t";
  481.     };
  482.  
  483.     while(<FP>) {
  484.          chop;
  485.  
  486.          if( $_ =~ /_Identification_/i ) {
  487.              $in_id = 1;
  488.          }
  489.  
  490.          if( $in_id > 0 ) {
  491.  
  492.              $buf = '';
  493.  
  494.              if( $_ =~ /^[\s]+version[s]*[\s]+(.*?)$/mi ) {
  495.  
  496.                  $buf = "($1)";
  497.                  $in_id = 3;
  498.  
  499.              } elsif( $_ =~ /^[\s]+release[\s]+(.*?)$/mi ) {
  500.  
  501.                  $buf = "($1)";
  502.                  $in_id = 3;
  503.  
  504.              } elsif( $_ =~ /product[s]?[\s]{8,}(.*?)$/mi ) {
  505.  
  506.                  $buf = ": $1";
  507.                  $in_id = 2;
  508.  
  509.              } elsif( $in_id == 2 && $_ =~ /^[\s]{22,}/m ) {
  510.  
  511.                  $buf = $_;
  512.              }
  513.  
  514.              if( $buf ne '' ) {
  515.                  $buf =~ s/^[\s]+//g;
  516.                  $buf =~ s/[\s]+$//g;
  517.                  $t .= " $buf";
  518.                  $t =~ s/\-[\ ]+\-//g;
  519.              }
  520.  
  521.              if( $in_id == 3 ) {
  522.                  last;
  523.              }
  524.          }
  525.     }
  526.     close(FP);
  527.  
  528.     $t =~ s/[\s]+$//g;
  529.     $t =~ s/\-[\ \d]+\-//;
  530.     return "$t";
  531. }
  532.  
  533.  
  534. # Return true from package include
  535. #
  536. 1;
  537.  
  538.